## Figure 2: Snapshot of Monthly-Varying Covid-19 Effects on Asian Hate Crimes

rm(list = ls())

setwd('/path/to/replication/')

library(data.table)
library(ggplot2)

## Figure 2 (a)
if (!file.exists('./output/coeff_deaths_jan_backup.RData')) {
  source('./code/figure2areg.R')
}

coeffs <- get(load('./output/coeff_deaths_jan_backup.RData'))

coeffs_z <- data.table(coeffs)
coeffs_z <- coeffs_z[month>='2018-01-01']

ggplot(coeffs_z,aes(x = month, y = effect)) +
  geom_point(size=0.75) +
  geom_hline(yintercept = 0, colour='red', linetype='longdash', size=0.25) +
  geom_vline(xintercept=as.Date('01-01-2020', format='%m-%d-%Y'),
             color='blue', linetype='dashed') +
  annotate("text", x = as.Date('10-01-2019', format='%m-%d-%Y'), y = 0.009, label = "Covid-19", colour='blue') +
  geom_linerange(aes(ymin = ci_low, ymax = ci_high)) +
  scale_x_date(breaks = "3 month", minor_breaks = "1 month", date_labels = '%Y-%m',
               limits = c(as.Date('12-01-2017', format='%m-%d-%Y'),
                          max = as.Date('05-01-2020', format='%m-%d-%Y')),
               expand=c(0,0)) +
  ylim(-0.005, 0.010) +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
        legend.position="none",
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black"
        ),axis.title.y = element_text(size = rel(1.2)),axis.text.y=element_text(size=12)) +
  xlab(NULL) +
  ylab('Effect of health threat on Asian hate crimes')
ggsave('./parallel_trends_deaths_jan_zoom.pdf', width=6, height=4.85)


## Figure 2 (b)
if (!file.exists('./output/coeff_economic_loss_backup.RData')) {
  source('./code/figure2breg.R')
}

coeffs <- get(load('./output/coeff_economic_loss_backup.RData'))

coeffs_z <- data.table(coeffs)
coeffs_z <- coeffs_z[month>='2018-01-01']

ggplot(coeffs_z,aes(x = month, y = effect)) +
  geom_point(size=0.75) +
  geom_hline(yintercept = 0, colour='red', linetype='longdash', size=0.25) +
  geom_vline(xintercept=as.Date('01-01-2020', format='%m-%d-%Y'),
             color='blue', linetype='dashed') +
  annotate("text", x = as.Date('10-01-2019', format='%m-%d-%Y'), y = 0.009, label = "Covid-19", colour='blue') +
  geom_linerange(aes(ymin = ci_low, ymax = ci_high)) +
  scale_x_date(breaks = "3 month", minor_breaks = "1 month", date_labels = '%Y-%m',
               limits = c(as.Date('12-01-2017', format='%m-%d-%Y'), max = as.Date('05-01-2020', format='%m-%d-%Y')),
               expand=c(0,0)) +
  ylim(-0.005,0.01) +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
        legend.position="none",
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black"
        ),axis.title.y = element_text(size = rel(1.2)),axis.text.y=element_text(size=12)) +
  xlab(NULL) +
  ylab('Effect of unemployment threat on Asian hate crimes')
ggsave('./parallel_trends_econ_zoom.pdf', width=6, height=4.85)